import java.util.Stack;
import java.util.StringTokenizer;
import java.util.*;



public class MyDC {
    public static int evaluate(StringBuilder b) {
        LinkedList<String> mList = new LinkedList<>();
        String[] postStr = b.toString().split(" ");
        int result;
        for (String s : postStr) {
            if (fuhao(s)) {
                if (!mList.isEmpty()) {
                    int num1 = Integer.valueOf(mList.pop());
                    int num2 = Integer.valueOf(mList.pop());
                    if (s.equals("/") && num1 == 0) {
                        System.out.println("除数不能为0");
                        return 0;
                    }
                    int newNum = cal(num2, num1, s);
                    mList.push(String.valueOf(newNum));
                }
            } else {
                mList.push(s);
            }
        }
        //if (!mList.isEmpty()) {

        //System.out.println("result: "+mList.pop());

        result=Integer.parseInt(mList.pop());
        // }

        return result;
    }

    private static boolean fuhao(String a) {
        if (a.equals("+") || a.equals("-") || a.equals("/") || a.equals("*")
                || a.equals("(") || a.equals(")")) {
            return true;
        }
        return false;
    }
    /*private static int priority(String s) {

        switch (s) {

            case "+":

                return 1;

            case "-":

                return 1;

            case "*":

                return 2;

            case "/":

                return 2;

            case "(":

                return 3;

            case ")":

                return 3;

            default:

                return 0;

        }

    }*/

    private static int cal(int num1, int num2, String operator) {
        switch (operator) {
            case "+":
                return num1 + num2;
            case "-":
                return num1 - num2;
            case "*":
                return num1 * num2;
            case "/":
                return num1 / num2;
            default:
                return 0;
        }
    }
}

    /*private boolean isOperator(String token) {

        return (token.equals("+") || token.equals("-") ||

                token.equals("*") || token.equals("/"));

    }



    private int evalSingleOp(char operation, int op1, int op2) {

        int result = 0;



        switch (operation) {

            case ADD:

                result = op1 + op2;

                break;

            case SUBTRACT:

                result = op1 - op2;

                break;

            case MULTIPLY:

                result = op1 * op2;

                break;

            case DIVIDE:

                result = op1 / op2;

        }



        return result;

    }

}*/